package za.co.johanmynhardt.jee.producer;

import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;

import za.co.johanmynhardt.jee.repository.PostRepository;
import za.co.johanmynhardt.jee.entity.Post;

/**
 * @author johan.mynhardt@thumbtribe.mobi
 * @version 2011.0721
 *          Time: 11:50 PM
 */
@ManagedBean
public class PostProducer {
	@Inject
	@PostRepository
	EntityManager entityManager;

	@Named
	@RequestScoped
	public Post getPost(Long id) {
		return (Post) entityManager.createQuery("select p from Post p where p.id = :id")
				.setParameter("id", id)
				.getSingleResult();
	}
}
